<template>
    <div class="wrapper">
        <el-row>
            <el-col :span="24">
                <common-card>
                    <template #header>
                        <div style="font-family: Roboto-Thin; padding: 20px; color: #fff">
                                <span style="font-size: 20px; display: inline-block; width: 100%">已发布消息列表
                                </span>


                            <span style="font-size: 14px; display: inline-block; width: 100%; margin-top: 10px">消息列表</span>

                        </div>

                    </template>

                    <template #main>
<!--                        <el-row style="margin-bottom: 15px" type="flex" align="middle">-->
<!--                            <el-input-->
<!--                                    clearable-->
<!--                                    size="mini"-->
<!--                                    @input="handlesearch"-->
<!--                                    class="tableSearch"-->
<!--                                    placeholder="课题名称"-->
<!--                                    prefix-icon="el-icon-search"-->
<!--                                    v-model="subjectName">-->
<!--                            </el-input>-->
<!--                            <el-input-->
<!--                                    clearable-->
<!--                                    size="mini"-->
<!--                                    @input="handlesearch"-->
<!--                                    class="tableSearch"-->
<!--                                    placeholder="教师姓名"-->
<!--                                    prefix-icon="el-icon-search"-->
<!--                                    v-model="teacherName">-->
<!--                            </el-input>-->

<!--                        </el-row>-->

                        <el-table
                                v-loading="tableLoading"
                                :max-height="height"
                                :data="tableData"
                                stripe
                                style="width: 100%">

                            <el-table-column
                                    prop="groupname"
                                    label="小组名称">
                            </el-table-column>

                            <el-table-column
                                    prop="content"
                                    label="小组信息内容">
                            </el-table-column>
                            <el-table-column
                                    prop="teachername"
                                    label="发布老师">
                            </el-table-column>

                        </el-table>
                    </template>
                </common-card>
            </el-col>
        </el-row>
        <add-dialog :dialog-visible="isAdd" :is-edit="isEdit" @closeDialog="isOpenDialog(false)"
                    :news-data="newsData" @fresh="fetchNewsByStudent"/>
    </div>
</template>

<script>
    import CommonCard from '../../components/Cards/CommonCard';
    import addDialog from './addDialog'
    import * as scoreManage from '@/api/scoreManage';
    import * as newsManage from '@/api/newsManage';
    import Cookie from "js-cookie";


    export default {
        name: 'index',
        components: {
            CommonCard,
            addDialog
        },
        data() {
            return {
                total: 0,
                currentPage: 1,
                departmentData: {},
				subjectData: {},
                tableLoading: true,
                height: '',
                isAdd: false,
                isEdit: false,
                isTeacher: false,
                tableData: [],
                userRes: {},
                teacherID: '',
                studentID: '',
                teacherusername: '',
                newsData: {},
                codeUrl: '111111',
                reportUrl: '1111',
                commitData: {
                    studentid: '',
                    teacherid: '',
                    subjectid: ''
                },
                gridData: []
            };

        },
        methods: {
            async fetchNewsByStudent() {
                console.log(this.teacherid);
                try {
                    let resInfo = JSON.parse(Cookie.get("userInfo"));
                    console.log(resInfo);
                    if (resInfo.role === 2) {
                        this.studenID = resInfo.token;
                        console.log(resInfo.token);
                        this.tableLoading = true;
                        if (this.teacherID) {
                            this.isTeacher = true;
                        }
                        const res = await newsManage.selectByCondition({studentid: resInfo.token});
                        console.log(res.msg);
                        this.tableData = res.msg;
                    }
                } catch (e) {
                    console.log(e)
                } finally {
                    this.tableLoading = false;
                }
            },
            isOpenDialog(isOpen, isEdit) {
                this.isAdd = isOpen;
                this.isEdit = isEdit;
            },
            handleClose() {
                this.$emit('closeDialog');
            },
            handleFresh() {
                this.$emit('fresh');
            },
            copyClick(row, column, cell, event) {
                this.$refs.popover4.showPopper = false;
                // document.body.click()
            }
        },
        created () {
            this.height = window.innerHeight - 150;
            // this.getTeacherInfo();
            this.fetchNewsByStudent();
        }
        }
</script>

<style scoped>
    .wrapper {
        padding: 0 15px;
    }

    .tableSearch {
        width: 221px;
    }

    .tableSearch >>> .el-input__inner {
        border-radius: 415px;
    }

    .btn {
        margin-right: 7px;
    }
</style>